<!DOCTYPE html>
<html>

<div th:replace="common/jsCssRef :: jsfJsCssRef"></div>

<body class="bgf6">

<div th:replace="common/head :: jsfHeader"></div>

<div class="main-body pb100">
    <div class="container pt10">
        <div class="dflx sbt">
            <div th:replace="common/left :: jsfLeft"></div>

            <div class="body-right">
                <div class="bread-nav bgff">
                    <ul class="dflx">
                    </ul>
                </div>

                    <div class="bgff mt10" id="app">
                        <div class="wrap">
                            <!--筛选条件/操作-->
                            <div class="row">
                                <div class="col-md-4">
                                    <input type="text" class="form-control" id="areaName" placeholder="请输入一级导航名称"><br>
                                    <button type="button" id="search" class="btn btn-primary f12" @click="addNav()"> 新增</button>
                                </div>
                            </div>

                            <form/>

                            <!--表格部分-->
                            <table class="table th52 f14 table-bordered mt20 table-hover" id="cityPlanTable">
                                <template>
                                    <el-table
                                            ref="multipleTable"
                                            :data="plans"
                                            tooltip-effect="dark"
                                            style="width: 100%"
                                            @selection-change="handleSelectionChange">


                                        <el-table-column
                                                label="ID"
                                                width="50">
                                            <template slot-scope="scope">{{ scope.row.id }}</template>
                                        </el-table-column>
                                        <el-table-column
                                                prop="navname"
                                                label="导航名称"
                                                width="150">
                                        </el-table-column>

                                        <el-table-column label="操作" width="160">
                                            <template slot-scope="scope">
                                                <el-button
                                                        type="success"
                                                        v-if="scope.row.status == 2"
                                                        size="mini"
                                                        @click="handleYunying(scope.$index, scope.row)">启用</el-button>

                                                <el-button
                                                        type="danger"
                                                        v-if="scope.row.status == 1"
                                                        size="mini"
                                                        @click="handleJinyong(scope.$index, scope.row)">禁用</el-button>

                                                <el-link type="primary" :href="'/view/toAddNavChild?navId=' + scope.row.id">&nbsp;&nbsp;子级菜单</el-link>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                </template>

                            </table>

                        </div>
                    </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">

    $(document).ready(function () {
        $('#areaLi').addClass('active');
    });
    
    function toAddPlan() {
        window.location.href = '/view/addArea';
    }


    var statusPlanObj = {
        '1' : '启用中',
        '2' : '已禁用'
    }
    

    var appPage = new Vue({
        el : '#app',
        data : {
            plans:[],
            multipleSelection: [],
            currentPage : 1,
            totalPage : 1,
            pageSize : 100
        },
        created : function() {
            this.loadPlanList();
        },
        computed : {

        },
        methods : {
            addNav : function() {

                if ($('#areaName').val() == '') {
                    alert('请输入一级导航');
                    return;
                }

                let that = this;
                $.ajax({
                    'url' : '/user/addNav',
                    'dataType' : 'json',
                    'type' : 'get',
                    'data' : {
                        navName : $('#areaName').val(),
                        level : 1,
                        parentId : 0
                    },
                    'success' : function (result) {
                        if (result.code != 1000) {
                            alert(result.message);
                            return;
                        }
                        alert('添加成功');
                        $('#areaName').val(''),
                        that.loadPlanList();
                    },
                    'error' : function (result) {
                    }
                });
            },
            loadPlanList : function () {
                let that = this;
                $.ajax({
                    'url' : '/user/queryFirstNav',
                    'dataType' : 'json',
                    'type' : 'get',
                    'data' : {
                    },
                    'success' : function (result) {
                        if (result.code != 1000) {
                            alert(result.message);
                            return;
                        }

                        appPage.plans = result.data;
                    },
                    'error' : function (result) {
                    }
                });
            },
            handleSelectionChange :  function (val) {
                this.multipleSelection = val;
            },

            handleYunying: function(index, row) {
                this.$confirm('确定运营'+row.areaName+'?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    jinyong(row.id, 1);

                }).catch(() => {
                        this.$message({
                        type: 'info',
                        message: '已取消'
                    });
                });

            },

            handleJinyong : function (index, row) {
                this.$confirm('确定禁用'+row.navname+'?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    jinyong(row.id, 2);

            }).catch(() => {
                    this.$message({
                    type: 'info',
                    message: '已取消'
                });
            });
            }

        }
    })
    
    function jinyong(id, status) {
        $.ajax({
            'url' :'/user/modiyNav',
            'dataType' : 'json',
            'type' : 'post',
            'data' : {
                'navId' : id,
                'status' : status
            },
            'success' : function (result) {
                if (result.code != 1000) {
                    alert(result.message);
                    return;
                }

                appPage.loadPlanList();
            },
            'error' : function (result) {
            }
        });

    }
    
    function resetParam() {
        $("#planNumber").val("")
        $("#datepicker").val("")
        document.getElementById("planStatus").options[0].selected = true;
        document.getElementById("originUnit").options[0].selected = true;
    }
    
    function delPlanSign(planId) {
        $.ajax({
            'url' : contentPath + '/cityPlan/delete',
            'dataType' : 'json',
            'type' : 'get',
            'data' : {
                'planId' : planId
            },
            'success' : function (result) {
                if (result.code != 1000) {
                    alert(result.message);
                    return;
                }

                window.location.reload();
            },
            'error' : function (result) {
            }
        });
    }


    $('#datepicker').fdatepicker({
        format: 'yyyy-mm-dd'
    });


</script>
</body>
</html>